from rest_framework.test import APITransactionTestCase

from apps.app_aai_proxy.managers import aai_proxy_configs


PRIVATE_KEY = """
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMdAyu0+PxMj8MWz
7nLUIddDuVgu/2ywAv7T2I9VTWetlWcBT9nZme4bqvi8QYIHl+/npnwpUzeMclLD
8kHOHvKhFum3XbvwSd2AxhH2yeogzOqsw+CkCy2AaHv2bDMrzObDckIOFpv+8bPm
5LA2i0hkdqb4YT5TfP24rIZsONUxAgMBAAECgYAwmwKlmwCh96t9XuY1BsB2laO5
+kT+y3T/msgCNwnZ18NRTEWhW+6r4f30DWBhit6qfDTlpuMQ8ubUf84x9Ukg8l5C
GCKjs7RL0MLw6kOwOT2sq42fzug9KgKTNnP7R8QQUBp3ZY+znAPzvPotmIggvC5S
rda7R/mW6uelCO2z0QJBAPPEqNhaOhJacFizYYHuD9+sC7c7DZcJa/N7HBSwZe7s
eak7YmG6JJ0HKzmBqYUNIGdJSfjREzGrlg1DjUoqnT0CQQDRQE+5lF0UXQ8kqoei
0o6kYPC+9Rk+S0179Sc+SSMGBs7gCuj12/3Aj2AykYCze5sZ/+ur78e+ea/59fwW
FP8FAkEA23QYbW4NCajRq4kSJ16ie8LvaS2ItoiM3s3eIeIMYmQRwwDrOP/TJmrl
xwesDVQb7+BS7+WJWhYXKCnAcRycIQJAFMAe59VZoaJU1RsAFlpxAMYIObeOiEnp
Zih6ese/7GISc89BKNhnAoh1Tq51J9dTGzHwyf0ePrpMhCorlHkCjQJANDqZTTW0
hR9+eDmG0kA1FQo4ldskYuv9AuB1agAz5/WQ7OID7nK/hXVI0rz58QD6OCizNWzj
mx7IP6GUqgxmZA==
-----END PRIVATE KEY-----
"""

PUBLIC_KEY = """
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHQMrtPj8TI/DFs+5y1CHXQ7lY
Lv9ssAL+09iPVU1nrZVnAU/Z2ZnuG6r4vEGCB5fv56Z8KVM3jHJSw/JBzh7yoRbp
t1278EndgMYR9snqIMzqrMPgpAstgGh79mwzK8zmw3JCDhab/vGz5uSwNotIZHam
+GE+U3z9uKyGbDjVMQIDAQAB
-----END PUBLIC KEY-----
"""

def init_proxy_configs():
    aai_proxy_configs.set(name=aai_proxy_configs.ConfigName.JWT_PRIVATE_KEY.value, value=PRIVATE_KEY)
    aai_proxy_configs.set(name=aai_proxy_configs.ConfigName.JWT_PUBLIC_KEY.value, value=PUBLIC_KEY)


class ProxyAPITransactionTestCase(APITransactionTestCase):
    def assertKeysIn(self, keys: list, container):
        for k in keys:
            self.assertIn(k, container)

    def assertFailedResponse(self, status_code: int, code: int, response):
        self.assertEqual(response.status_code, status_code)
        self.assertKeysIn(['success', 'code', 'message', 'data'], response.data)
        self.assertEqual(response.data['code'], code)
        self.assertIs(response.data['success'], False)

    def assert_is_subdict_of(self, sub: dict, d: dict):
        for k, v in sub.items():
            if k in d and v == d[k]:
                continue
            else:
                self.fail(f'{sub} is not sub dict of {d}, Not Equal key is {k}, {v} != {d.get(k)}')

        return True
